/*
 * @Author: song
 * @Description:技能配置 一个技能对应一个
 * @Date: 2024年04月22日 星期一 19:04:44
 * @Modify:
 */

using System;
using System.Collections.Generic;
using SCore.Function.Fixed;
using Function.SerializedPropertyAttribute;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
using UnityEngine.Serialization;

namespace Function.SkillEditor.Runtime
{
#if UNITY_EDITOR
    [CustomEditor(typeof(SkillRunLine))]
    public class SkillRunLineEditor : ObjectDrawEditor<SkillRunLine>
    {
    }
#endif
    public class SkillRunLine : ScriptableObject
    {
        [Head("lineID")] public int _lineId;

        [Head("结束帧")] public int _lengthFrame;

        [Head("技能轨道")] public List<SkillTrack> _skillTracks = new List<SkillTrack>();

        /// <summary>
        /// 当前运行的帧
        /// </summary>
        [NonSerialized] private fp _runFrame = fp.Zero;

        /// <summary>
        /// 当前开始的Time
        /// </summary>
        [NonSerialized] private fp _startTime;

        public void Tick(fp dt)
        {
            //需要先执行条件判断的轨道
            for (int offset = _skillTracks.Count - 1; offset >= 0; offset--)
            {
                _skillTracks[offset].Tick(_runFrame);
            }

            _runFrame += 1;
        }

        public bool Finish()
        {
            return _runFrame > _lengthFrame;
        }

        public void RefreshMaxFrame()
        {
            int maxFrame = 0;
            foreach (var skillTrack in _skillTracks)
            {
                if (maxFrame < skillTrack.GetMaxFrame())
                {
                    maxFrame = skillTrack.GetMaxFrame();
                }
            }

            _lengthFrame = maxFrame;
        }
    }
}